<template>
	<view class="margin-sm">
		<view class="padding bg-main margin-bottom-sm border-radius dflex-b" @click="toFeedbackType">
			<view class="dflex">
				<view class="iconfont iconmingxi ft-base margin-right-xs"></view>
				<view class="fwbd">常见问题｜我的反馈</view>
			</view>
			
			<view class="dflex margin-left">
				<view class="iconfont iconjiantou-01 fwb"></view>
			</view>
		</view>

		<!-- 标题 -->
		<view class="padding bg-main margin-bottom-sm border-radius dflex-b">
			<input type="text" maxlength="20" class="wh-full" v-model="postData.title" placeholder="标题(不超过20个字)" />
		</view>

		<view class="padding bg-main margin-bottom-sm border-radius">
			<textarea class="ft-black w-full fs-sm" v-model="postData.content" placeholder="请输入反馈内容"></textarea>
			<!-- 上传图片 -->
			<use-uploads class="pos-r" @upload="uploadImgs"></use-uploads>
		</view>
		
		<!-- 联系方式 -->
		<view class="padding bg-main margin-bottom-sm border-radius dflex-b">
			<input type="text" maxlength="30" class="wh-full" v-model="postData.contacts" placeholder="联系方式(手机号)" />
		</view>
		
		<!-- 提交操作 -->
		<view class="padding w-full margin-top">
			<view class="dflex-b border-radius-big">
				<view class="tac padding-tb-sm fwb flex1 bg-base" @click="submit">提交</view>
			</view>
		</view>
		

		<!-- 世华圣医版权 -->
		<use-copyright></use-copyright>
	</view>
</template>
<script>
	import {feed_back} from "@/js_sdk/apis/user.js"
	export default {
		data() {
			return {
				feedbackTypePopup: false,
				feedbackType: {},
				feedbackTypeDatas: [],
				isubmit: false,
				postData: {
					title: '',
					imgs:[],
					content: '',
					contacts: ''
				}
			};
		},
		computed: {
			userInfo(){
				return this.$store.state.user.userInfo
			},
			isLogin(){
				return this.$store.getters['user/hasLogin']
			}
		},
		methods: {
			uploadImgs(options) {
				if (options.length > 0) this.postData.imgs = options;
				console.log('uploadImgs', this.postData.imgs);
			},
			submit() {
				let _this = this;
				
				if (!this.postData.title) {
					this.$api.msg('请填写标题');
					return;
				}
				if (!this.postData.content) {
					this.$api.msg('请填写反馈内容');
					return;
				}
				if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.postData.contacts))){
					uni.showToast({title: '请填写正确手机号码',icon:"none"});
					return false; 
				} 
				if (this.isubmit) return;

				this.isubmit = true;
				uni.showModal({
					title: '提示',
					content: '确认提交？',
					success: (res) => {
						this.isubmit = false;
						if (res.confirm) {
							let temp=JSON.parse(JSON.stringify(this.postData))
							temp.imgs=temp.imgs.toString()
							temp.userId=this.userInfo.userId
							feed_back(temp).then(res => {
								this.$api.alert('反馈成功，谢谢！', () => {
									this.$api.back();
								});
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			toFeedbackType() {
				uni.navigateTo({
					url:"faq"
				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: $page-color-base;
	}

	/* 商品区 */
	.goods-area {
		&:last-child {
			margin-bottom: 0;
		}

		image {
			width: 180rpx;
			height: 180rpx;
		}
	}
</style>
